using System;
using System.Configuration;
using System.Diagnostics;
using Core.IocHelpers;

namespace Core.Settings
{
  ///<summary>
  ///  Core (global) access to the WPF App settings
  ///</summary>
  [AutoRegister]
  public class AppSettings : IAppSettings
  {
    private static ApplicationSettingsBase _internalSource;

    #region IAppSettings Members

    const string SourceXmlCommunityFilePathKey = "SourceXmlCommunityFilePath";

    ///<summary>
    ///</summary>
    public event EventHandler<EventArgs> FilePathChanged;

    [UserScopedSetting]
    [DebuggerNonUserCode]
    [DefaultSettingValue("")]
    public string SourceXmlCommunityFilePath
    {
      get { return ((string) (_internalSource[SourceXmlCommunityFilePathKey])); }
      set
      {
        var save = ((string) _internalSource[SourceXmlCommunityFilePathKey]) != value;
        if (save)
        {
          _internalSource[SourceXmlCommunityFilePathKey] = value;
          _internalSource.Save();

          if (FilePathChanged != null)
          {
            FilePathChanged(this, EventArgs.Empty);
          }
        }
      }
    }

    ///<summary>
    ///</summary>
    public ApplicationSettingsBase Source
    {
      get { return _internalSource; }
    }

    ///<summary>
    ///</summary>
    ///<param name="source"></param>
    public void LinkToSource(ApplicationSettingsBase source)
    {
      _internalSource = source;
    }

    #endregion
  }
}